package org.myspringmvc.web.servlet.view;

import org.myspringmvc.web.servlet.View;
import org.myspringmvc.web.servlet.ViewResolver;

import java.util.Locale;

/**
 * @Author 海晨忆
 * @Des 内部资源的视图解析器
 * @Date 2025/7/17 10:24
 */
public class InternalResourceViewResolver implements ViewResolver {
    private String prefix;
    private String suffix;

    public InternalResourceViewResolver() {
    }

    public InternalResourceViewResolver(String prefix, String suffix) {
        this.prefix = prefix;
        this.suffix = suffix;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }

    /**
     * 将逻辑视图名字转换为物理视图
     *
     * @param viewName
     * @param locale
     * @return
     * @throws Exception
     */
    @Override
    public View resolveViewName(String viewName, Locale locale) throws Exception {
        InternalResourceView view = new InternalResourceView("text/html;charset=utf-8", prefix + "/" + viewName + suffix);
        return view;
    }
}
